package org.jeecg.modules.third.kaiyunshukedaikai;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.apache.http.HttpEntity;
import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class DriverTest {

    /**
     * 编辑车辆信息接口测试
     * @param appid
     * @param appsecret
     * @throws UnsupportedEncodingException
     */
    public static void edit(String appid, String appsecret){

        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("id_card_no","130125198612174510");
        params.put("real_name","韩明");
        params.put("gender","1");
        params.put("qual_cert_id","111");
        params.put("mobile","15512346022");
        params.put("carrier_mobile","180111111");
        params.put("id_pic1_pic_url","");
        params.put("id_pic2_pic_url","");
        params.put("driver_lic_pic_url","");
        params.put("driver_lic_side_pic_url","");
        params.put("qual_cert_pic_url","");
        params.put("carrier_id_card_no","42011111111122233");
        params.put("quasi_driving_type","A2");


        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params),"utf-8");
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String result =
                    TestHttpClientUtil.httpPost("http://106.15.190.131:8100/openapi/car/ApiDriver/edit?appid="+appid+
                            "&_aop_strtotime="+_aop_strtotime, reqEntity);

            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 新增车辆接口测试
     * @param appid
     * @param appsecret
     * @throws UnsupportedEncodingException
     */
    public static void add(String appid, String appsecret){

        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("id_card_no","130125198612174510");
        params.put("real_name","韩明");
        params.put("gender","1");
        params.put("qual_cert_id","111");
        params.put("mobile","15512346022");
        params.put("carrier_mobile","180111111");
        params.put("id_pic1_pic_url","");
        params.put("id_pic2_pic_url","");
        params.put("driver_lic_pic_url","");
        params.put("driver_lic_side_pic_url","");
        params.put("qual_cert_pic_url","");
        params.put("carrier_id_card_no","42011111111122233");
        params.put("quasi_driving_type","A2");

        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        System.out.println("新增驾驶人接口参数："+params);
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params),"utf-8");
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String result =
                    TestHttpClientUtil.httpPost("http://106.15.190.131:8100/openapi/car/ApiDriver/add?appid="+appid+
                            "&_aop_strtotime="+_aop_strtotime, reqEntity);

            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        edit("hnxzeeuvIm73","0ec49d56b0de3bd489bb97a915127fdd1df642ef");
    }

    public static void getStatus(String appid, String appsecret){
        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("mobile","15512348019");
//        params.put("carrier_id_card_no","42011111111122233");
        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        String _aop_signature = data.get("_aop_signature");
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params),"utf-8");
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String url = "http://139.224.227.123:8100/openapi/car/ApiDriver/getStatus?appid="+appid+
//            String url = "http://127.0.0.1:8080/openapi/car/ApiDriver/getStatus?appid="+appid+
                    "&_aop_strtotime="+_aop_strtotime+"&_aop_signature="+_aop_signature;
            Map<String,Object> map = new HashMap<>();
            map.put("mobile","15512348019");
//            map.put("carrier_id_card_no","42011111111122233");
            String result =
                    HttpUtil.get(url,map);

            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void retrieve(String appid, String appsecret){
        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("mobile","1342222");
        params.put("carrier_id_card_no","42011111111122233");
        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        String _aop_signature = data.get("_aop_signature");
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params));
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String url = "http://127.0.0.1:8080/openapi/car/ApiDriver/retrieve?appid="+appid+
                    "&_aop_strtotime="+_aop_strtotime+"&_aop_signature="+_aop_signature;
            Map<String,Object> map = new HashMap<>();
            map.put("mobile","1342222");
            map.put("carrier_id_card_no","42011111111122233");
            String result =
                    HttpUtil.get(url,map);

            System.out.println(result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
